package org.ezplatform.office.meeting.notice.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.core.pagination.PropertyFilter;
import org.ezplatform.core.service.BaseService;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.meeting.common.util.MeetingSendMsgUtils;
import org.ezplatform.office.meeting.info.entity.ApplyRecord;
import org.ezplatform.office.meeting.info.entity.MeetingScope;
import org.ezplatform.office.meeting.info.service.ApplyRecordService;
import org.ezplatform.office.meeting.info.service.MeetingScopeService;
import org.ezplatform.office.meeting.notice.dao.NoticeInfoDao;
import org.ezplatform.office.meeting.notice.entity.NoticeInfo;
import org.ezplatform.office.meeting.notice.entity.NoticeTurnover;
import org.ezplatform.office.meeting.setting.boardroom.entity.BoardroomSet;
import org.ezplatform.office.meeting.setting.boardroom.service.BoardroomSetService;
import org.ezplatform.util.DateUtils;
import org.ezplatform.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

@Service
@Transactional
public class NoticeInfoService extends BaseService<NoticeInfo, String>{
    
	private final static Logger LOGGER = LoggerFactory.getLogger(NoticeInfoService.class);
	
    @Autowired
    private NoticeInfoDao dao;
    
    @Autowired
    private ApplyRecordService applyRecordService;
    
    @Autowired
    private MeetingScopeService meetingScopeService;
    
    @Autowired
    private NoticeTurnoverService noticeTurnoverService;
    
    @Autowired
	private UserApiService userApiService;
	
	@Autowired
    private BoardroomSetService boardroomSetService;
	
	@Autowired
	private MeetingSendMsgUtils meetingSendMsgUtils;
    
    private int currentPageNum = 0;
    private int pageSizeNum = 0;
    private int startLimitNum = 0;
    
    @Override
    protected JpaBaseDao<NoticeInfo, String> getEntityDao() {
        return dao;
    }

    /**
     * 会议申请推送会议通知给会议室管理员
     * @param entity
     * @param msList
     */
    public void  saveNoticeInfoIsApply(ApplyRecord applyRecord, List<MeetingScope> msList) {
        String applyRecordId = applyRecord.getId();
        for(MeetingScope ms : msList){
            NoticeInfo noticeInfo = new NoticeInfo();
            noticeInfo.setApplyRecordId(applyRecordId);
            noticeInfo.setNoticeUserId(ms.getScopevalue());
            noticeInfo.setCorpId(applyRecord.getCorpId());
            noticeInfo.setType(0);
            noticeInfo.setStatus(0);
            this.save(noticeInfo);
        }
    }
    
    /**
     * 获取会议通知显示卡片的信息
     * @param corpId
     * @param userId
     * @param type  0:全部 1：我发起的  2：我参加的 
     * @param showNumber
     * @return
     */
    public List<Map<String, Object>> getNoticeList(String corpId, String userId) {
    	Map<String, Object> paramMap = new HashMap<String, Object>();
    	List<Map> userL=this.findByListNativeQuery("select user_status as userStatus,is_delete as isDelete from sys_user where id='"+userId+"'", "");
		if(userL!=null && userL.size()>0) {
			Map userStatus=userL.get(0);
			if("offDuty".equals(userStatus.get("userStatus"))||"1".equals(userStatus.get("isDelete")+"")) {
				return new ArrayList<Map<String, Object>>();
			}
		}
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omni.id noticeInfoId,omapr.createdBy,sysu4.user_name createdName,sysu.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,omapr.name applyRecordName,");
        sql.append(" omapr.start_time startTime,ombs.name boardroomName,omapr.boardroom_id boardroomId, omapr.is_signed,omapr.signed_type,omni.status as status,omni.reason,sysu2.user_name turnoverUserName,omapr.meeting_way meetingWay,omni.attend_way attendway,");
        sql.append(" sysu3.user_name receiveUserName,'" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type,omni.turnover_user_id turnoverUserId,omni.receive_user_id receiveUserId,omapr.address,qsmeeting.emeeUrl emeeUrl,qsmeeting.attendUrl attendUrl,omapr.end_time endTime ");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join sys_user sysu on sysu.id = omni.inviter");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu2 on sysu2.id = omni.turnover_user_id");
        sql.append(" left join sys_user sysu3 on sysu3.id = omni.receive_user_id");
        sql.append(" left join sys_user sysu4 on sysu4.id = omapr.createdBy");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" left join oa_meeting_qs qsmeeting on qsmeeting.meetingApplyId =omapr.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.status != 1 and omni.is_delete='0'");
        
        sql.append(" and omni.notice_user_id= :userId  ");
        sql.append(" and omapr.end_time > :nowDateTime ");
        String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
        paramMap.put("nowDateTime", nowDateTime);
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);

        sql.append(" order by startTime asc ");
        LOGGER.debug("--getNoticeList--sql:"+sql);
        LOGGER.debug("--nowDateTime:"+nowDateTime);
        LOGGER.debug("--corpId:"+corpId);
        LOGGER.debug("--userId:"+userId);
        List<Map> list = super.findByListNativeQuery(sql.toString(), "", paramMap);
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        if(CollectionUtils.isNotEmpty(list)) {
        	LOGGER.debug("--list.size():"+list.size());
        	List<Map> itemList = null;
        	String time = null;
        	int i = 0;
        	Map<String, Object> map = null;
        	for(Map m : list) {
        		if(time == null) {
        			time = StringUtils.null2String(m.get("startTime")).substring(0, 10);
        			itemList = new ArrayList<>();
        			itemList.add(m);
        		}else if(time.equals(StringUtils.null2String(m.get("startTime")).substring(0, 10))) {
        			itemList.add(m);
        		}else if(!time.equals(StringUtils.null2String(m.get("startTime")).substring(0, 10))) {
        			map = new LinkedHashMap<String, Object>();
        			map.put("time", time);
        			map.put("list", itemList);
        			result.add(map);
        			time = StringUtils.null2String(m.get("startTime")).substring(0, 10);
        			itemList = new ArrayList<>();
        			itemList.add(m);
        		}
        		i++;
        		if(list.size() == i) {
        			map = new LinkedHashMap<String, Object>();
        			map.put("time", time);
        			map.put("list", itemList);
        			result.add(map);
        		}
        	}
        }
        return result;
    }
    
    /**
     * 获取会议通知数
     * @param corpId
     * @param userId
     * @return
     */
    public int getNoticeListNum(String corpId, String userId) {
    	int num = 0;
    	Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omni.id noticeInfoId,omapr.createdBy,sysu4.user_name createdName,sysu.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,omapr.name applyRecordName,");
        sql.append(" omapr.start_time startTime,ombs.name boardroomName,omapr.boardroom_id boardroomId, omapr.is_signed,omapr.signed_type,omni.status as status,omni.reason,sysu2.user_name turnoverUserName,omapr.meeting_way meetingWay,omni.attend_way attendway,");
        sql.append(" sysu3.user_name receiveUserName,'" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type,omni.turnover_user_id turnoverUserId,omni.receive_user_id receiveUserId,omapr.address,qsmeeting.emeeUrl emeeUrl,qsmeeting.attendUrl attendUrl,omapr.end_time endTime ");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join sys_user sysu on sysu.id = omni.inviter");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu2 on sysu2.id = omni.turnover_user_id");
        sql.append(" left join sys_user sysu3 on sysu3.id = omni.receive_user_id");
        sql.append(" left join sys_user sysu4 on sysu4.id = omapr.createdBy");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" left join oa_meeting_qs qsmeeting on qsmeeting.meetingApplyId =omapr.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.status != 1 and omni.is_delete='0'");
        
        sql.append(" and omni.notice_user_id= :userId  ");
        sql.append(" and omapr.end_time > :nowDateTime ");
        String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
        paramMap.put("nowDateTime", nowDateTime);
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);

        sql.append(" order by startTime asc ");
        LOGGER.debug("--getNoticeList--sql:"+sql);
        LOGGER.debug("--nowDateTime:"+nowDateTime);
        LOGGER.debug("--corpId:"+corpId);
        LOGGER.debug("--userId:"+userId);
        List<Map> list = super.findByListNativeQuery(sql.toString(), "", paramMap);
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        if(CollectionUtils.isNotEmpty(list)) {
        	LOGGER.debug("--list.size():"+list.size());
        	
        	num = list.size();
        }
        return num;
    }
    
    /**
     * 获取会议通知显示卡片的信息(PC门户,分离后的)
     * @param corpId
     * @param userId
     * @param showNumber
     * @return
     */
    public List<Map> getNoticeListMenHu(String corpId, String userId, String showNumber) {
    	LOGGER.debug("--getNoticeListMenHu----");
    	Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omni.id noticeInfoId,omapr.createdBy,sysu4.user_name createdName,sysu.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,omapr.name applyRecordName,");
        sql.append(" omapr.start_time startTime,ombs.name boardroomName,omapr.boardroom_id boardroomId, omapr.is_signed,omapr.signed_type,omni.status as status,omni.reason,sysu2.user_name turnoverUserName,omapr.meeting_way meetingWay,");
        sql.append(" sysu3.user_name receiveUserName,'" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type,omni.turnover_user_id turnoverUserId,omni.receive_user_id receiveUserId,omapr.address");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join sys_user sysu on sysu.id = omni.inviter");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu2 on sysu2.id = omni.turnover_user_id");
        sql.append(" left join sys_user sysu3 on sysu3.id = omni.receive_user_id");
        sql.append(" left join sys_user sysu4 on sysu4.id = omapr.createdBy");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
        sql.append(" and omapr.end_time > :nowDateTime ");
        String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
        paramMap.put("nowDateTime", nowDateTime);
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
        sql.append(" order by startTime asc ");
        LOGGER.debug("--getNoticeListMenHu---nowDateTime:"+nowDateTime);
        LOGGER.debug("--getNoticeListMenHu---corpId:"+corpId);
        LOGGER.debug("--getNoticeListMenHu---userId:"+userId);
        LOGGER.debug("--getNoticeListMenHu---sql:"+sql);
        return super.findByListNativeQuery(sql.toString(), "", paramMap, 0, Integer.parseInt(showNumber));
    }
    
    /**
     * 获取会议通知显示卡片的信息(PC门户,分离后的)
     * @param corpId
     * @param userId
     * @param showNumber
     * @return
     */
    public List<Map> getNoticeListMenHu_new(String corpId, String userId, String showNumber) {
    	LOGGER.debug("--getNoticeListMenHu_new----");
    	List<Map> result = new ArrayList();
    	
    	StringBuffer sql = new StringBuffer();
    	sql.append("select omapr.id applyRecordid,omapr.start_time startTime ");
    	sql.append("from ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,");
    	sql.append("emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address ");
    	sql.append("FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
    	sql.append(" UNION ALL ");
    	sql.append("(SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,");
    	sql.append("ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address ");
    	sql.append(" FROM oa_meeting_apply_record ar,");
    	sql.append("(SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record ");
    	sql.append("WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
    	sql.append("WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )");
    	sql.append(")omapr  where omapr.status = 1 and omapr.end_time > :nowDateTime order by startTime asc ");
    	
    	Map<String, Object> paramMap = new HashMap<String, Object>();
    	String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
        paramMap.put("nowDateTime", nowDateTime);
    	
        LOGGER.debug("---sql:"+sql);
        
    	List<Map> list = super.findByListNativeQuery(sql.toString(), "", paramMap);
    	if(list!=null&&list.size()>0) {
    		StringBuffer ids = new StringBuffer();
    		for(int i=0;i<list.size();i++) {
    			ids.append("'"+list.get(i).get("applyRecordid")+"',");
    		}
    		String idsstr = ids.toString();
    		if(idsstr.endsWith(",")) {idsstr = idsstr.substring(0,idsstr.length()-1);}
    		sql = new StringBuffer();
    		sql.append("select omapr.id applyRecordid,omni.id noticeInfoId,omapr.createdBy,sysu4.user_name createdName,sysu.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,omapr.name applyRecordName,");
            sql.append(" omapr.start_time startTime,ombs.name boardroomName,omapr.boardroom_id boardroomId, omapr.is_signed,omapr.signed_type,omni.status as status,omni.reason,sysu2.user_name turnoverUserName,omapr.meeting_way meetingWay,");
            sql.append(" sysu3.user_name receiveUserName,'" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type,omni.turnover_user_id turnoverUserId,omni.receive_user_id receiveUserId,omapr.address");
            sql.append(" from oa_meeting_notice_info omni");
            sql.append(" join ");
            sql.append("  ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address");
            sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
            sql.append("  UNION ALL");
            sql.append("   (SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address");
            sql.append("   FROM oa_meeting_apply_record ar,");
            sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
            sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
            sql.append(" on omni.apply_record_id = omapr.id");
            sql.append(" left join sys_user sysu on sysu.id = omni.inviter");
            sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
            sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
            sql.append(" left join sys_user sysu2 on sysu2.id = omni.turnover_user_id");
            sql.append(" left join sys_user sysu3 on sysu3.id = omni.receive_user_id");
            sql.append(" left join sys_user sysu4 on sysu4.id = omapr.createdBy");
            sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
            sql.append(" where omni.corp_id=:corpId and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
            sql.append(" and omapr.id in("+idsstr+") ");
            paramMap = new HashMap<String, Object>();
            paramMap.put("corpId", corpId);
            paramMap.put("userId", userId);
            sql.append(" order by startTime asc ");

            LOGGER.debug("---corpId:"+corpId);
            LOGGER.debug("---userId:"+userId);
            LOGGER.debug("--sql:"+sql);
            result = super.findByListNativeQuery(sql.toString(), "", paramMap, 0, Integer.parseInt(showNumber));
            
    	}
    	
    	
    	return result;
    	
    }
    
    /**
     * 查询我发起的会议列表
     * @param corpId
     * @param userId
     * @return
     */
    public Page<Map> findNoticeInfoListByMe(Pageable pageable, String corpId, String userId,Map<String, Object> paramMap) {
        StringBuffer sql = new StringBuffer();
        sql.append("select * from (select omar.id,omar.createdDate,omar.name meetingName,omar.start_time startTime,omar.address,omar.end_time endTime,u2.user_name memoName,");
        sql.append(" omar.is_cycle isCycle,ombs.name boardroomName,omar.boardroom_id boardroomId,u.user_name emceeName,omar.status,ombs.is_approve isApprove");
        sql.append(" from oa_meeting_apply_record omar ");
        sql.append(" left join oa_meeting_boardroom_set ombs on omar.boardroom_id=ombs.id");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue=omar.emcee_user");
        sql.append(" left join sys_user u on oms.scopeValue=u.id");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue=omar.memo_user");
        sql.append(" left join sys_user u2 on oms2.scopeValue=u2.id");
        sql.append(" where omar.corp_id=:corpId and omar.createdBy=:userId");
        sql.append(" and omar.status in (1,3,4,5) and omar.is_sync=1)a where 1=1 ");
        Map<String, Object> param = new HashMap<String, Object>();
        if(StringUtils.isNotBlank((String)paramMap.get("startTime"))) {
        	param.put("startTime", paramMap.get("startTime"));
        	if(StringUtils.isNotBlank((String)paramMap.get("endTime"))) {
        		param.put("endTime", paramMap.get("endTime"));
        		sql.append(" and startTime<=:endTime and endTime>=:startTime");
        	}else sql.append(" and endTime>=:startTime");
        }else if(StringUtils.isNotBlank((String)paramMap.get("endTime"))) {
    		sql.append(" and startTime<=:endTime");
    		param.put("endTime", paramMap.get("endTime"));
    	}
       
        if(StringUtils.isNotBlank((String)paramMap.get("meetingName"))) {
        	sql.append(" and meetingName like :meetingName");
        	param.put("meetingName", "%"+paramMap.get("meetingName")+"%");
        }
        if(StringUtils.isNotBlank((String)paramMap.get("boardroomName"))) {
        	sql.append(" and boardroomName like :boardroomName");
        	param.put("boardroomName", "%"+paramMap.get("boardroomName")+"%");
        }
        if(StringUtils.isNotBlank((String)paramMap.get("status"))) {
        	sql.append(" and status = :status");
        	param.put("status", paramMap.get("status"));
        }
        sql.append(" order by startTime desc,createdDate desc");
        param.put("corpId", corpId);
        param.put("userId", userId);
        return super.findByPageNativeSQL(pageable, sql.toString(), param);
    }

    /**
     * 获取会议通知列表数据
     * @param corpId
     * @param name
     * @param userId 
     * @param nowDateTime 
     * @param showNumber 
     * @param type 0.审批,1.参会通知,2.审批和参会通知 
     * @return
     */
    public Map<String, List<Map>> getNoticeInfoSetList(String corpId, String name, String userId,String nowDateTime,String showNumber,String type) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omapr.createdBy,sysu2.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,sysu.user_name userName,omapr.name applyRecordName,");
        sql.append("omapr.start_time startTime,omapr.end_time endTime,ombs.name boardroomName,omni.id noticeInfoId,omapr.is_signed,omapr.signed_type,");
        sql.append("omni.type type,omni.status as status,omni.reason,nt.receive_user_name receiveUserName, '" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,cycle_id,is_cycle,cycle_type,createdBy,NAME,end_time,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.cycle_id,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.end_time,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu on sysu.id = omapr.createdBy");
        sql.append(" left join sys_user sysu2 on sysu2.id = omni.inviter");
        sql.append(" left join oa_meeting_notice_turnover nt on omni.id=nt.notice_info_id");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
        if(!"2".equals(type)){
        	 sql.append(" and omni.type=:type ");
        	 paramMap.put("type", type);
        	 if("1".equals(type)){
        		 sql.append(" and omapr.start_time > :nowDateTime ");
        		 paramMap.put("nowDateTime", nowDateTime);
        	 }
        }else{
        	 sql.append(" and (omni.type=0 or ( omni.type=1 and omapr.start_time > :nowDateTime ))");
        	 paramMap.put("nowDateTime", nowDateTime);
        }
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
        sql.append(" order by startTime asc ");

        List<Map> list = new ArrayList<>();
        if(StringUtils.isNotEmpty(showNumber)){
            list = super.findByListNativeQuery(sql.toString(), "", paramMap, 0, Integer.parseInt(showNumber));
        }else{
            list = super.findByListNativeQuery(sql.toString(), "", paramMap);
        }
        //添加转交人
        Map<String, String> pools = new HashMap<String, String>();
        List<NoticeTurnover> ntList = noticeTurnoverService.findListByProperty("corpId", corpId, corpId);
        if(CollectionUtils.isNotEmpty(ntList)) {
        	String firstKey = "";
        	for(NoticeTurnover nt : ntList) {
        		firstKey = StringUtils.null2String(nt.getApplyRecordId()) + StringUtils.null2String(nt.getReceiveUserId());
        		String turnoverUserName = StringUtils.null2String(nt.getTurnoverUserName());
        		if(pools.get(firstKey) == null) {
        			pools.put(firstKey, turnoverUserName);
        		}else {
        			pools.put(firstKey, pools.get(firstKey) + "," + turnoverUserName);
        		}
        	}
        }
        Map<String, List<Map>> result = new LinkedHashMap<String, List<Map>>();;
        if(CollectionUtils.isNotEmpty(list)) {
        	List<Map> itemList = null;
        	String time = null;
        	int i = 0;
        	for(Map m : list) {
        		String firstKey = StringUtils.null2String(m.get("applyRecordid")) + StringUtils.null2String(userId);
        		m.put("turnoverUserName", pools.get(firstKey));
        		if(time == null) {
        			time = StringUtils.null2String(m.get("startTime")).substring(0, 10);
        			itemList = new ArrayList<>();
        			itemList.add(m);
        		}else if(time.equals(StringUtils.null2String(m.get("startTime")).substring(0, 10))) {
        			itemList.add(m);
        		}else if(!time.equals(StringUtils.null2String(m.get("startTime")).substring(0, 10))) {
        			result.put(time, itemList);
        			time = StringUtils.null2String(m.get("startTime")).substring(0, 10);
        			itemList = new ArrayList<>();
        			itemList.add(m);
        		}
        		i++;
        		if(list.size() == i) result.put(time, itemList);
        	}
        }
        return result;
    }
    
    public List<Map> getNoticeInfoSetList2(String corpId, String name, String userId,String nowDateTime,String showNumber,String type) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omapr.createdBy,oms.scopeValue emceeUserId,sysu.user_name userName,omapr.name applyRecordName,");
        sql.append("omapr.start_time startTime,omapr.end_time endTime,ombs.name boardroomName,omni.id noticeInfoId,omapr.is_signed,omapr.signed_type,");
        sql.append("omni.type type,omni.status as status,nt.receive_user_name receiveUserName, '" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,cycle_id,is_cycle,cycle_type,createdBy,NAME,end_time,is_signed,signed_type,emcee_user,boardroom_id,STATUS");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.cycle_id,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.end_time,ar.is_signed,ar.signed_type,ar.emcee_user,ar.boardroom_id,ar.STATUS");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join sys_user sysu on sysu.id = omapr.createdBy");
        sql.append(" left join oa_meeting_notice_turnover nt on omni.id=nt.notice_info_id");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
        if(!"2".equals(type)){
        	 sql.append(" and omni.type=:type ");
        	 paramMap.put("type", type);
        	 if("1".equals(type)){
        		 sql.append(" and omapr.start_time > :nowDateTime ");
        		 paramMap.put("nowDateTime", nowDateTime);
        	 }
        }else{
        	 sql.append(" and (omni.type=0 or ( omni.type=1 and omapr.start_time > :nowDateTime ))");
        	 paramMap.put("nowDateTime", nowDateTime);
        }
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
//        if(StringUtils.isNotEmpty(name)){
//            sql.append(" and (omapr.name like :name or ombs.name like :name)");
//            paramMap.put("name", "%"+name+"%");
//        }
        sql.append(" order by startTime asc ");

        List<Map> list = new ArrayList<>();
        if(StringUtils.isNotEmpty(showNumber)){
            list = super.findByListNativeQuery(sql.toString(), "", paramMap, 0, Integer.parseInt(showNumber));
        }else{
            list = super.findByListNativeQuery(sql.toString(), "", paramMap);
        }
        //添加转交人
        Map<String, String> pools = new HashMap<String, String>();
        List<NoticeTurnover> ntList = noticeTurnoverService.findListByProperty("corpId", corpId, corpId);
        if(CollectionUtils.isNotEmpty(ntList)) {
        	String firstKey = "";
        	for(NoticeTurnover nt : ntList) {
        		firstKey = StringUtils.null2String(nt.getApplyRecordId()) + StringUtils.null2String(nt.getReceiveUserId());
        		String turnoverUserName = StringUtils.null2String(nt.getTurnoverUserName());
        		if(pools.get(firstKey) == null) {
        			pools.put(firstKey, turnoverUserName);
        		}else {
        			pools.put(firstKey, pools.get(firstKey) + "," + turnoverUserName);
        		}
        	}
        }
        if(CollectionUtils.isNotEmpty(list)) {
        	for(Map m : list) {
        		String firstKey = StringUtils.null2String(m.get("applyRecordid")) + StringUtils.null2String(userId);
        		m.put("turnoverUserName", pools.get(firstKey));
        	}
        }
        return list;
    }
    
    /**
     * 获取会议通知列表数据（移动端门户会议助手）
     * @param corpId
     * @param name
     * @param userId 
     * @param nowDateTime 
     * @param showNumber 
     * @param type 0.审批,1.参会通知,2.审批和参会通知 
     * @return
     */
    public List<Map> getNoticeInfoList(String corpId, String name, String userId,String nowDateTime,String showNumber,String type) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omapr.createdBy,oms.scopeValue emceeUserId,sysu.user_name userName,omapr.name applyRecordName,");
        sql.append("omapr.start_time startTime,omapr.end_time endTime,ombs.name boardroomName,omni.id noticeInfoId,omapr.is_signed,omapr.signed_type,");
        sql.append("omni.type type,omni.status as status,nt.receive_user_id receiveUserId, nt.receive_user_name receiveUserName, '" + userId + "' as user_id,omapr.is_cycle isCycle,omapr.cycle_type cycleType");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,cycle_id,is_cycle,cycle_type,createdBy,NAME,end_time,is_signed,signed_type,emcee_user,boardroom_id,STATUS");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.cycle_id,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.end_time,ar.is_signed,ar.signed_type,ar.emcee_user,ar.boardroom_id,ar.STATUS");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join sys_user sysu on sysu.id = omapr.createdBy");
        sql.append(" left join oa_meeting_notice_turnover nt on omni.id=nt.notice_info_id");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
        if(!"2".equals(type)){
        	 sql.append(" and omni.type=:type ");
        	 paramMap.put("type", type);
        	 if("1".equals(type)){
        		 sql.append(" and omapr.start_time > :nowDateTime ");
        		 paramMap.put("nowDateTime", nowDateTime);
        	 }
        }else{
        	 sql.append(" and (omni.type=0 or ( omni.type=1 and omapr.start_time > :nowDateTime ))");
        	 paramMap.put("nowDateTime", nowDateTime);
        }
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
        if(StringUtils.isNotEmpty(name)){
            sql.append(" and (omapr.name like :name or ombs.name like :name)");
            paramMap.put("name", "%"+name+"%");
        }
        sql.append(" order by omni.type asc,omni.createdDate desc ");

        List<Map> list = new ArrayList<>();
        if(StringUtils.isNotEmpty(showNumber)){
            list = super.findByListNativeQuery(sql.toString(), "", paramMap, 0, Integer.parseInt(showNumber));
        }else{
            list = super.findByListNativeQuery(sql.toString(), "", paramMap);
        }
        return list;
    }
    
    /**
     * 获取我发出的会议通知列表数据
     * @param corpId
     * @param name
     * @param userId 
     * @param nowDateTime 
     * @param showNumber 
     * @param type 0.审批,1.参会通知,2.审批和参会通知 
     * @return
     */
    public List<Map> getNoticeInfoSetListByOneself (String corpId, String userId, String nowDateTime) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omapr.id applyRecordid,omapr.createdBy,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,sysu.user_name userName,omapr.name applyRecordName,");
        sql.append("omapr.start_time startTime,omapr.end_time endTime,ombs.name boardroomName,omni.id noticeInfoId,omapr.is_signed,omapr.signed_type, '" + userId + "' as user_id,");
        sql.append("omni.type type,omni.status as status,case when omapr.start_time > :nowDateTime then 1 ");
        sql.append("when omapr.start_time <= :nowDateTime and omapr.end_time >= :nowDateTime then 2 end meetingStatus,omapr.is_cycle,omapr.cycle_type from");
        sql.append("  ((SELECT id,start_time,cycle_id,is_cycle,cycle_type,createdBy,NAME,end_time,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,corp_id ");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.cycle_id,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.end_time,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.corp_id ");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("   (SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t");
        sql.append("   WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" left join oa_meeting_notice_info omni on omni.apply_record_id = omapr.id and omni.status != 1 ");
        sql.append("	and omni.is_delete='0' and omni.type=1 and omni.notice_user_id=:userId");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu on sysu.id = omapr.createdBy");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" where omapr.corp_id=:corpId and omapr.status in (1,4) and omapr.createdBy=:userId");
		sql.append(" and omapr.end_time >= :nowDateTime ");
        sql.append(" order by omapr.start_time asc ");
        paramMap.put("nowDateTime", nowDateTime);
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
        return super.findByListNativeQuery(sql.toString(), "", paramMap);
    }
    
    /**
     * 修改会议通知状态
     * @param noticeInfoId
     * @param status
     */
    public void updateNoticeInfoStatus(String noticeInfoId, int status) {
        this.dao.updateNoticeInfoStatus(noticeInfoId,status);
    }
    
    /**
     * 删除会议通知
     * @param noticeInfoId
     * @param status
     */
    public void deleteByListIds(List<String> list) {
        if(list!=null && list.size()>0){
            this.dao.deleteList(list);
        }
    }
    
    /**
     * 删除会议审批通知
     */
    public void deleteApproveNotice(String applyRecordId) {
    	this.dao.deleteApproveNotice(applyRecordId);
    }
    
    public NoticeInfo findByApplyrecordId(String applyRecordId, String noticeUserId, String type){
    	return this.dao.findByApplyrecordId(applyRecordId, noticeUserId, Integer.parseInt(type));
    }
    
    /**
     * 查询已转交会议的人的通知信息
     * @param applyRecordId
     * @param turnoverUserId
     * @return
     */
    public NoticeInfo findByTurnoverUserId(String applyRecordId, String turnoverUserId) {
    	return this.dao.findByTurnoverUserId(applyRecordId, turnoverUserId);
    }

    /**
     * 获取需参加会议的通知
     * @param applyRecordId
     * @param noticeUserId
     * @param type
     * @return
     */
    public NoticeInfo findAttendByApplyrecordId(String applyRecordId, String noticeUserId, String type){
    	return this.dao.findAttendByApplyrecordId(applyRecordId, noticeUserId, Integer.parseInt(type));
    }
    
    /**
     * 发送会议审批通过通知
     * @param entity
     * @param type
     * @param token 
     */
    public void addNoticeInfoByApplyrecord(ApplyRecord applyRecord, int type, String token) {
        String corpId = applyRecord.getCorpId();
        String applyRecordId = applyRecord.getId();
        List<String> userIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, token);
        if(userIdList!=null && userIdList.size()>0){
            List<NoticeInfo> list = new ArrayList<NoticeInfo>();
            for(String userId : userIdList){
                NoticeInfo n = new NoticeInfo();
                n.setApplyRecordId(applyRecordId);
                n.setNoticeUserId(userId);
                n.setType(type);
                n.setStatus(0);
                n.setCorpId(corpId);
                list.add(n);
            }
            this.save(list);
        }
    }

    /**
     * 新建参会通知数据
     * @param userIdList
     * @param applyRecordId
     * @param corpId
     */
    public void addNoticeInfo(List<String> userIdList, String applyRecordId, String corpId) {
    	addNoticeInfo(userIdList, applyRecordId, null, corpId);
    }
    
    /**
     * 新建参会通知数据
     * @param userIdList
     * @param applyRecordId
     * @param inviter
     * @param corpId
     * @return
     */
	public OperationResult addNoticeInfo(List<String> userIdList, String applyRecordId, String inviter, String corpId) {
		try {
			if(userIdList!=null && userIdList.size()>0){
			    List<NoticeInfo> list = new ArrayList<NoticeInfo>();
			    for(String userId : userIdList){
			        NoticeInfo n = new NoticeInfo();
			        n.setApplyRecordId(applyRecordId);
			        n.setNoticeUserId(userId);
			        n.setType(1);
			        n.setCorpId(corpId);
			        if(StringUtils.isNotBlank(inviter)) {
			        	n.setStatus(9);
			        	n.setInviter(inviter);
			        }else {
			        	n.setStatus(0);
			        }
			        list.add(n);
			    }
			    this.save(list);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return OperationResult.buildFailureResult("保存失败");
		}
		return OperationResult.buildSuccessResult("保存成功");
	}
	
	public List<String> getTurnoverUseIds(String applyRecordId, String corpId){
		return this.dao.getTurnoverUseIds(applyRecordId, corpId);
	}
	
	/**
	 * 会议转交，用户替换
	 * @param applyRecord
	 * @param token
	 * @param oldUserId 原用户
	 * @param turnoverUserId 转交用户
	 */
	public void changeUser(ApplyRecord applyRecord, String token, String turnoverUserId, String receiveUserId, String receiveUserName){
        Map<String, Object> map = new HashMap<String, Object>();
		//主持人
        List<String> eScopeList = new ArrayList<>();
        eScopeList.add(applyRecord.getEmceeUser());
        List<MeetingScope> emceeUserList = this.meetingScopeService.getMeetingScopeList("oa_meeting_apply_record", "emcee_user", eScopeList,true);
        //纪要员
        List<String> mScopeList = new ArrayList<>();
        mScopeList.add(applyRecord.getMemoUser());
        List<MeetingScope> memoUserList = this.meetingScopeService.getMeetingScopeList("oa_meeting_apply_record", "memo_user", mScopeList,true);
        if(emceeUserList!=null && emceeUserList.size()>0){
            for(MeetingScope ms : emceeUserList){
               if(turnoverUserId.equals(ms.getScopevalue())) {
            	   this.meetingScopeService.updateScopeValue(receiveUserId, receiveUserName, ms.getId());
               }
            }
        }
        if(memoUserList!=null && memoUserList.size()>0){
            for(MeetingScope ms : memoUserList){
            	if(turnoverUserId.equals(ms.getScopevalue())) {
            		this.meetingScopeService.updateScopeValue(receiveUserId, receiveUserName, ms.getId());
                }
            }
        }
    }
    
    /**
     * 新建参会通知数据(周期会议)
     * @param userIdList
     * @param applyRecordId
     * @param corpId
     */
    public void addCycleNoticeInfo(List<ApplyRecord> arCycleList, List<String> userIdList, String applyRecordId, String corpId) {
        if(CollectionUtils.isNotEmpty(arCycleList)){
            for(ApplyRecord ar : arCycleList) {
            	if(!applyRecordId.equals(ar.getId()))
            		addNoticeInfo(userIdList, ar.getId(), corpId);
            }
        }
    }
    
    public void deleteByApplyrecord(ApplyRecord applyRecord) {
        this.dao.deleteByApplyrecordId(applyRecord.getId());
    }
    
    public void deleteByApplyrecord(String... recordIds) {
        this.dao.deleteByApplyrecordId(recordIds);
    }

    public void deleteByApplyrecord(ApplyRecord applyRecord,int type) {
        this.dao.deleteByApplyrecordId(applyRecord.getId(),type);
    }

    public OperationResult deleteNoticeInfo(String[] ids) {
        OperationResult result = null;
        if(ids!=null){
            List<String> list = Arrays.asList(ids);
            this.dao.updateNoticeInfoList(list);
        }
        return result.buildSuccessResult("删除成功");
    }

    /**
     * 查询用户参会信息
     * @param applayRecord:会议id
     * @param type 0:未反馈、已请假 1:确认参加
     * @return
     */
    public String getNoticeUserName(String applayRecord, int type) {
        String userName = "";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer("");
        sql.append(" select omni.notice_user_id userId,sysu.user_name userName from oa_meeting_notice_info omni");
        sql.append(" left join sys_user sysu on omni.notice_user_id = sysu.id");
        sql.append(" where omni.type in(1) and omni.apply_record_id =:applayRecord");
        paramMap.put("applayRecord", applayRecord);
        if(type==0){
            sql.append(" and omni.status in(0,3)");
        }else if(type==1){
            sql.append(" and omni.status in(2)");
        }
        sql.append(" order by sysu.user_name asc");
        
        List list = super.getQueryByNativeSQL(sql.toString(), paramMap).getResultList();
        if(list!=null && list.size()>0){
            for(int i=0;i<list.size();i++){
                Object[] obj = (Object[]) list.get(i); 
                userName += obj[1]+",";
            }
        }
        if(StringUtils.isNotEmpty(userName)){
        	userName = userName.substring(0, userName.length()-1);
        }
        return userName;
    }

    /**
     * 获取会议通知列表数据
     * @param localPageable
     * @param corpId
     * @param name
     * @param userId 
     * @param corpId 
     * @param type 0:审批会议通知   1:参会会议通知
     * @param condition 
     * @return
     */
    public List<Map> getNoticeInfoSetList(String currentPage, String pageSize, String userId, String corpId,String isCountType, String condition, int type,String nowDateTime) {
        List<Map> list = new ArrayList<>();
        StringBuffer sql = new StringBuffer();
        Map<String, Object> params = new HashMap<>();
        params.put("corpId", corpId);
        params.put("userId", userId);
        params.put("noticeType", type);
        sql.append("select omapr.id applyRecordid,omapr.createdBy,sysu.user_name userName,omapr.name applyRecordName,");
        sql.append("omapr.start_time startDateTime,omapr.end_time endDateTime,ombs.name boardroomName,omni.id noticeInfoId,");
        sql.append("omni.type type,omni.status as status,nt.receive_user_name receiveUserName,omapr.is_cycle isCycle,omapr.cycle_type cycleType from oa_meeting_notice_info omni ");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,cycle_id,is_cycle,cycle_type,createdBy,NAME,end_time,is_signed,signed_type,emcee_user,boardroom_id,STATUS");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.cycle_id,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.end_time,ar.is_signed,ar.signed_type,ar.emcee_user,ar.boardroom_id,ar.STATUS");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id ");
        sql.append("left join sys_user sysu on sysu.id = omapr.createdBy ");
        sql.append("left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append("left join oa_meeting_notice_turnover nt on omni.id=nt.notice_info_id ");
        sql.append("where omni.corp_id =:corpId and omapr.status = 1 and omni.notice_user_id in(:userId) and omni.status != 1 and omni.is_delete='0' ");
        sql.append("and omni.type =:noticeType ");
        if(type == 1){
        	sql.append("and omapr.start_time>:startTime ");
            params.put("startTime", nowDateTime);
        }
        
        if(StringUtils.isNotEmpty(condition)){
            sql.append("and (omapr.name like :condition ) ");
            params.put("condition", "%"+condition+"%");
        }
        sql.append("order by startDateTime asc ");

        if(isCountType.equals("0")){
            if(StringUtils.isNotEmpty(currentPage)){
                this.currentPageNum = Integer.valueOf(currentPage);
            }
            if(StringUtils.isNotEmpty(pageSize)){
                this.pageSizeNum = Integer.valueOf(pageSize);
            }
           this.startLimitNum= (this.currentPageNum-1) * this.pageSizeNum;
            list = super.findByListNativeQuery(sql.toString(), "", params, this.startLimitNum, this.pageSizeNum);
        }else{
            list = super.findByListNativeQuery(sql.toString(), "", params);
        }

        if(list!=null && list.size()>0){
        	Locale localeCN = Locale.SIMPLIFIED_CHINESE;
            SimpleDateFormat format = new SimpleDateFormat("E",localeCN);
            for(Map<String,Object> map : list){
                String startDateTime = String.valueOf(map.get("startDateTime"));
                String endDateTime = String.valueOf(map.get("endDateTime"));
            	String week = format.format(DateUtils.parseDate(startDateTime));
                String day = DateUtils.formatDate(DateUtils.parseDate(startDateTime), "MM")+"."+DateUtils.formatDate(DateUtils.parseDate(startDateTime), "dd");
                map.put("startDate", startDateTime.substring(5,startDateTime.length()));
                map.put("endDate", endDateTime.substring(5,endDateTime.length()));
                map.put("day", day);
                map.put("week", week);
                map.put("startTime", startDateTime.substring(11, 16));
                map.put("endTime", endDateTime.substring(11, 16));
            }
        }
        return list;
    }

    /**
     * 查询会议申请列表数coun
     * @param userId
     * @param corpId
     * @param string
     * @param condition
     * @param i
     * @return
     */
    public int getNoticeInfoSetListCount(String userId, String corpId, String isCountType, String condition, int type,String nowDateTime) {
        int count = 0;
        List<Map> list = this.getNoticeInfoSetList("", "", userId, corpId, isCountType, condition, type,nowDateTime);
        if(list!=null && list.size()>0){
            count = list.size();
        }
        return count;
    }
    
    /**
     * 查询会议申请列表数coun
     * @param userId
     * @param corpId
     * @param nowDateTime
     * @param type
     * @return
     */
    public int getNoticeInfotCount(String userId, String corpId, String nowDateTime, String type) {
    	Map<String, Object> paramMap = new HashMap<String, Object>();
    	StringBuffer sql = new StringBuffer();
        sql.append("select count(omni.id) from oa_meeting_notice_info omni ");
        sql.append(" join oa_meeting_apply_record omapr on omni.apply_record_id = omapr.id");
        sql.append(" where omni.corp_id=:corpId and omapr.status in(0,1) and omni.notice_user_id in(:userId) and omni.status not in(1) and omni.is_delete='0'");
        if(!"2".equals(type)){
       	 sql.append(" and omni.type=:type ");
       	 paramMap.put("type", type);
       	 if("1".equals(type)){
       		 sql.append(" and omapr.start_time>:nowDateTime ");
       		 paramMap.put("nowDateTime", DateUtils.parseTime(nowDateTime));
       	 }
       }else{
       	 sql.append(" and (omni.type=0 or (omni.type=1 and omapr.start_time>:nowDateTime))");
       	 paramMap.put("nowDateTime", DateUtils.parseTime(nowDateTime));
       }
       paramMap.put("corpId", corpId);
       paramMap.put("userId", userId);
        
        Query query = super.getQueryByNativeSQL(sql.toString(), paramMap);
        int count = Integer.parseInt(query.getSingleResult().toString());
    	return count;
    }

    /**
     * 保存会议通知
     * @param id
     * @param status 
     * @param reason
     */
    public void editNoticeInfo(String id, int status, String reason) {
        NoticeInfo noticeInfo = this.findOne(id);
        noticeInfo.setStatus(status);
        noticeInfo.setReason(reason);
        this.save(noticeInfo);
    }

    /**
     * 查询用户参会信息
     * @param applayRecord:会议id
     * @param type 0:未反馈、已请假 1:确认参加
     * @return
     */
    public List getNoticeUserList(String applayRecord, int type) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer("");
        sql.append(" select omni.notice_user_id userId,sysu.user_name userName,sysu.outside_link ,sysu.dd_uid from oa_meeting_notice_info omni");
        sql.append(" left join sys_user sysu on omni.notice_user_id = sysu.id");
        sql.append(" where omni.type in(1) and omni.apply_record_id =:applayRecord");
        paramMap.put("applayRecord", applayRecord);
        if(type==0){
            sql.append(" and omni.status in(0,3)");
        }else if(type==1){
            sql.append(" and omni.status in(2)");
        }
        sql.append(" order by sysu.user_name asc");
        
        List list = super.getQueryByNativeSQL(sql.toString(), paramMap).getResultList();
        return list;
    }
    
    public Page getReceiptStatistics(Pageable pageable, String applyrecordId, String noticeType, String corpId) {
    	return getReceiptStatistics(pageable, applyrecordId, noticeType, null, corpId);
    }
   
    /**
     * 回执统计查询
     * @param pageable
     * @param applyrecordId
     * @param noticeType
     * @param corpId
     * @return
     */
    public Page getReceiptStatistics(Pageable pageable, String applyrecordId, String noticeType, String userName, String corpId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT t.userId,t.org_name,t.userName,t.status,t.reason,t.applyStatus,t.attendway,t.inviter,t.receiveUser,t.turnoverUser from (");
        sql.append("SELECT omni.notice_user_id userId,so.org_name,su.user_name userName,omni.status as status,omni.reason,omar.status applyStatus,omni.attend_way attendway,");
        sql.append(" (select su1.user_name from sys_user su1 where omni.receive_user_id = su1.id) receiveUser,");
        sql.append(" (select su2.user_name from sys_user su2 where omni.turnover_user_id = su2.id) turnoverUser,");
        sql.append(" (select su3.user_name from sys_user su3 where omni.inviter = su3.id) inviter");
        sql.append(" FROM oa_meeting_notice_info omni");
        sql.append(" LEFT JOIN oa_meeting_apply_record omar ON omni.apply_record_id = omar.id");
        sql.append(" LEFT JOIN sys_user su ON omni.notice_user_id = su.id");
        sql.append(" LEFT JOIN sys_org_user sou ON omni.notice_user_id = sou.user_id AND sou.isMain = 1");
        sql.append(" LEFT JOIN sys_org so ON sou.org_id = so.id AND so.corp_id = :corpId");
        sql.append(" WHERE omni.apply_record_id = :applyrecordId AND omni.type = '1' ");
        paramMap.put("applyrecordId", applyrecordId);
        paramMap.put("corpId", corpId);
        if(StringUtils.isNotEmpty(userName)){//参会情况
            sql.append(" AND su.user_name like :userName ");
            paramMap.put("userName", "%" + userName + "%");
        }
        if(StringUtils.isNotEmpty(noticeType)){//参会情况
        	if("0".equals(noticeType)) {
        		sql.append(" AND omni.status not in (2,3,4)");
        	}else {
        		sql.append(" AND omni.status = :noticeType ");
                paramMap.put("noticeType", noticeType);
        	}
        }
        sql.append(" ) t where 1=1 ");
        List localList = new ArrayList();
        String sqlStr = PropertyFilter.getSqlByFilterAndPageable("t", sql.toString(), "t.userName ASC", localList, pageable);
        return super.findByPageNativeSQL(pageable, sqlStr, paramMap);
    }
    
    public void deleteNoticeInfo(List<String> noticeUserIdList, String applyRecordId, String corpId) {
    	this.dao.deleteNoticeInfo(noticeUserIdList, applyRecordId, corpId);
    }
    
    public void deleteNoticeInfoByApplyrecordId(String applyRecordId, String corpId) {
    	this.dao.deleteNoticeInfoByApplyrecordId(applyRecordId, corpId);
    }
    
    /**
	 * 根据接收人选人组件json获取邀请人的id集合，剔除已参会和已转交的人员
	 * @param jsonStr
	 * @return
	 */
    public List<String> getInviteUserIds(String jsonStr, List<String> aruList, List<String> turnoverUseIds) {
		List<String> result = new ArrayList<String>();
		JSONArray json = (JSONArray) JSONArray.parse(jsonStr);
	    if(json != null && json.size() > 0) {
	    	JSONObject jo = null;
	    	String userId = "";
	    	for(int i = 0; i < json.size(); i++) {
	    		jo = (JSONObject)json.get(i);
		    	userId = jo.getString("scopeValue");
		    	if(!aruList.contains(userId) && !turnoverUseIds.contains(userId)) {
		    		result.add(userId);
		    	}
	    	}
	    }
	    return result;
	}
    
    /**
     * 根据接收人选人组件json获取无需邀请人的id集合，包括已参会和已转交的人员
     * @param jsonStr
     * @param aruList
     * @param turnoverUseIds
     * @return
     */
    public List<Map<String,Object>> getUnInviteUserIdsAndNames(String jsonStr, List<String> aruList, List<String> turnoverUseIds) {
    	List<Map<String,Object>> result = new ArrayList<>();
		JSONArray json = (JSONArray) JSONArray.parse(jsonStr);
	    if(json != null && json.size() > 0) {
	    	JSONObject jo = null;
	    	String userId = "";
	    	String userName= "";
	    	Map<String,Object> ele=null;
	    	for(int i = 0; i < json.size(); i++) {
	    		ele=new HashMap<>();
	    		jo = (JSONObject)json.get(i);
		    	userId = jo.getString("scopeValue");
		    	userName=jo.getString("scopeName");
		    	if(aruList.contains(userId) || turnoverUseIds.contains(userId)) {
		    		ele.put("userId",userId);
		    		ele.put("userName",userName);
		    		result.add(ele);
		    	}
	    	}
	    }
	    return result;
	}
    
    /**
     * 给转交人推送消息
     * @param request
     * @param entity
     * @param userId
     * @param corpId
     */
    public void sendMessageToTurnoverUser(HttpServletRequest request, ApplyRecord entity, String sendUserId, 
    		List<String> userIdList, String corpId, String token) {
    	StringBuffer ids = new StringBuffer();
		StringBuffer jsonIds = new StringBuffer("[");
		for(int i = 0; i < userIdList.size(); i++) {
			if(i == userIdList.size() - 1) {
				ids.append(userIdList.get(i));
				jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"}]");
			}else {
				ids.append(userIdList.get(i) + ",");
				jsonIds.append("{\"10\":\"" + userIdList.get(i) + "\"},");
			}
		}
		jsonIds.append("]");
    	Map<String, Object> ds = new HashMap<>();
        ds.put("applyRecordId", entity.getId());
 		ds.put("meetingTitle", entity.getName());
 		ds.put("startTime", entity.getStartTime());
 		BoardroomSet room = null;
 		if(StringUtils.isNotEmpty(entity.getBoardroomId())) {
 			room = this.boardroomSetService.findOne(entity.getBoardroomId());
 		}
 		ds.put("boardroom", room == null ? (StringUtils.isNotBlank(entity.getAddress()) ? entity.getAddress() : "无") : room.getAddress());
        String userName = "";
        Map<String, Object> userInfo = this.userApiService.getUser(sendUserId, corpId,  "", token);
        if(userInfo != null){
            userName = StringUtils.null2String(userInfo.get("userName"));
        }
 		ds.put("userId", sendUserId);
 		ds.put("userName", userName);
 		ds.put("userOrg", userInfo.get("orgId"));
 		ds.put("type", "2");
 		ds.put("userIds", ids.toString());
        ds.put("orgIds", null);
        boolean mobilePush = false;
        boolean emailPush = false;
        boolean smsPublish = false;
		String mesgPush = entity.getMessagePush();
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
		this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, token);
        this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
        this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
        this.meetingSendMsgUtils.sendMessage(ds, jsonIds.toString(), corpId, token);
    }
    
    /**
	 * 根据选人组件(单选)json获取id,name
	 * @param jsonStr
	 * @return
	 */
    public Map<String, String> getUserIdAndName(String jsonStr) {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray json = (JSONArray) JSONArray.parse(jsonStr);
	    if(json != null && json.size() > 0) {
	    	JSONObject jo = (JSONObject)json.get(0);
	    	map.put("id", jo.getString("scopeValue"));
	    	map.put("name", jo.getString("scopeName"));
	    }
	    return map;
	}
	
    /**
	 * 获取会议通知显示卡片的信息(钉钉端)
	 * @param request
	 * @return
	 */
	public List<Map> getNoticeListDing(String currentPage, String pageSize, String userId,
            String corpId, String condition) {
		if(StringUtils.isNotEmpty(currentPage)){
            this.currentPageNum = Integer.valueOf(currentPage);
        }
        if(StringUtils.isNotEmpty(pageSize)){
            this.pageSizeNum = Integer.valueOf(pageSize);
        }
        this.startLimitNum= (this.currentPageNum-1) * this.pageSizeNum;
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select distinct omapr.id applyRecordid,omni.id noticeInfoId,omni.attend_way attendWay,omapr.createdBy,sysu.user_name inviter,oms.scopeValue emceeUserId,oms2.scopeValue memoUserId,omapr.name applyRecordName,");
        sql.append(" omapr.start_time startTime,ombs.name boardroomName,omapr.boardroom_id boardroomId,omapr.is_signed,omapr.signed_type,omni.status as status,omni.reason,sysu2.user_name turnoverUserName,omapr.meeting_way meetingWay,");
        sql.append(" sysu3.user_name receiveUserName,'" + userId + "' as user_id,omapr.is_cycle,omapr.cycle_type,omni.turnover_user_id turnoverUserId,omni.receive_user_id receiveUserId,omapr.address,");
        sql.append("qsmeeting.conferenceId qsmeetingId,qsmeeting.pcode1 emceeUserPass,qsmeeting.pcode2 attUserPass,qsuser.qsemail qsuserId,qsuser.qsusername qsusername");
        sql.append(" from oa_meeting_notice_info omni");
        sql.append(" join ");
        sql.append("  ((SELECT id,start_time,end_time,is_cycle,cycle_type,createdBy,NAME,is_signed,signed_type,emcee_user,memo_user,boardroom_id,STATUS,meeting_way,address");
        sql.append("   FROM oa_meeting_apply_record WHERE is_sync=1 AND STATUS = 1 AND is_cycle = 0)");
        sql.append("  UNION ALL");
        sql.append("   (SELECT ar.id,ar.start_time,ar.end_time,ar.is_cycle,ar.cycle_type,ar.createdBy,ar.NAME,ar.is_signed,ar.signed_type,ar.emcee_user,ar.memo_user,ar.boardroom_id,ar.STATUS,ar.meeting_way,ar.address");
        sql.append("   FROM oa_meeting_apply_record ar,");
        sql.append("  	( SELECT min( start_time ) start_time, cycle_id FROM oa_meeting_apply_record WHERE STATUS = 1 AND is_cycle = 1 GROUP BY cycle_id ) t ");
        sql.append("  WHERE ar.is_sync=1 and t.start_time = ar.start_time AND t.cycle_id = ar.cycle_id )) omapr");
        sql.append(" on omni.apply_record_id = omapr.id");
        sql.append(" left join sys_user sysu on sysu.id = omni.inviter");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue = omapr.emcee_user");
        sql.append(" left join oa_meeting_apply_record_scope oms2 on oms2.fieldDataValue = omapr.memo_user");
        sql.append(" left join sys_user sysu2 on sysu2.id = omni.turnover_user_id");
        sql.append(" left join sys_user sysu3 on sysu3.id = omni.receive_user_id");
        sql.append(" left join oa_meeting_boardroom_set ombs on omapr.boardroom_id =ombs.id ");
        sql.append(" left join oa_meeting_qs qsmeeting on omapr.id =qsmeeting.meetingApplyId ");
        sql.append(" left join oa_meeting_qsuser qsuser on qsuser.userId = '" + userId + "'");
        sql.append(" where omni.corp_id=:corpId and omapr.status = 1 and omni.notice_user_id = :userId and omni.status != 1 and omni.is_delete='0'");
        sql.append(" and omapr.end_time > :nowDateTime ");
        if(StringUtils.isNotBlank(condition)) {
			sql.append(" and omapr.name like :condition");
			paramMap.put("condition", "%"+ condition +"%");
		}
        sql.append(" order by startTime asc ");
        String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
        paramMap.put("nowDateTime", nowDateTime);
		paramMap.put("corpId", corpId);
		paramMap.put("userId", userId);
		return super.findByListNativeQuery(sql.toString(), "", paramMap, this.startLimitNum, this.pageSizeNum);
	}
	
	/**
     * 查询我发起的会议列表(钉钉端)
     * @param corpId
     * @param userId
     * @return
     */
    public List<Map> findNoticeInfoListByMeDing(String currentPage, String pageSize, String userId,
            String corpId, String condition) {
    	if(StringUtils.isNotEmpty(currentPage)){
            this.currentPageNum = Integer.valueOf(currentPage);
        }
        if(StringUtils.isNotEmpty(pageSize)){
            this.pageSizeNum = Integer.valueOf(pageSize);
        }
        this.startLimitNum= (this.currentPageNum-1) * this.pageSizeNum;
    	Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("select omar.id,omar.name meetingName,omar.start_time startTime,omar.address,omar.end_time endTime,");
        sql.append(" omar.is_cycle isCycle,ombs.name boardroomName,omar.boardroom_id boardroomId,u.user_name emceeName,omar.status,ombs.is_approve isApprove");
        sql.append(" from oa_meeting_apply_record omar ");
        sql.append(" left join oa_meeting_boardroom_set ombs on omar.boardroom_id=ombs.id");
        sql.append(" left join oa_meeting_apply_record_scope oms on oms.fieldDataValue=omar.emcee_user");
        sql.append(" left join sys_user u on oms.scopeValue=u.id");
        sql.append(" where omar.corp_id=:corpId and omar.createdBy=:userId");
        sql.append(" and omar.status in (1,3,4,5) and omar.is_sync=1");
        if(StringUtils.isNotBlank(condition)) {
			sql.append(" and omar.name like :condition");
			paramMap.put("condition", "%"+ condition +"%");
		}
        sql.append(" order by omar.start_time desc, omar.createdDate desc");
        paramMap.put("corpId", corpId);
        paramMap.put("userId", userId);
        return super.findByListNativeQuery(sql.toString(), "", paramMap, this.startLimitNum, this.pageSizeNum);
    }
    
    /**
     * 回执统计查询
     * @param pageable
     * @param applyrecordId
     * @param noticeType
     * @param corpId
     * @return
     */
    public List<Map> getReceiptStatisticsDing(String applyrecordId, String currentPage, String pageSize, String status,
            String corpId, String condition) {
    	if(StringUtils.isNotEmpty(currentPage)){
            this.currentPageNum = Integer.valueOf(currentPage);
        }
        if(StringUtils.isNotEmpty(pageSize)){
            this.pageSizeNum = Integer.valueOf(pageSize);
        }
        this.startLimitNum= (this.currentPageNum-1) * this.pageSizeNum;
        Map<String, Object> paramMap = new HashMap<String, Object>();
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT omni.notice_user_id userId,so.org_name,su.user_name userName,omni.status as status,omni.reason,omar.status applyStatus,omni.attend_way attendway,");
        sql.append(" (select su1.user_name from sys_user su1 where omni.receive_user_id = su1.id) receiveUser,");
        sql.append(" (select su2.user_name from sys_user su2 where omni.turnover_user_id = su2.id) turnoverUser,");
        sql.append(" (select su3.user_name from sys_user su3 where omni.inviter = su3.id) inviter");
        sql.append(" FROM oa_meeting_notice_info omni");
        sql.append(" LEFT JOIN oa_meeting_apply_record omar ON omni.apply_record_id = omar.id");
        sql.append(" LEFT JOIN sys_user su ON omni.notice_user_id = su.id");
        sql.append(" LEFT JOIN sys_org_user sou ON omni.notice_user_id = sou.user_id AND sou.isMain = 1");
        sql.append(" LEFT JOIN sys_org so ON sou.org_id = so.id AND so.corp_id = :corpId");
        sql.append(" WHERE omni.apply_record_id = :applyrecordId AND omni.type = '1' ");
        paramMap.put("applyrecordId", applyrecordId);
        if("0".equals(status)) {
        	sql.append(" AND (omni.status=0 or omni.status=9)");
        }else {
        	sql.append(" AND omni.status=:status");
        	paramMap.put("status", status);
        }
        paramMap.put("corpId", corpId);
        if(StringUtils.isNotEmpty(condition)){//参会情况
            sql.append(" AND su.user_name like :userName ");
            paramMap.put("userName", "%" + condition + "%");
        }
        List<Map> list = super.findByListNativeQuery(sql.toString(), "", paramMap, this.startLimitNum, this.pageSizeNum);
        return list;
    }
}